@import helper._
@import java.util.Optional
@import java.util.UUID

@import com.example.auction.transaction.api.TransactionInfoStatus
@(showInlineInstruction: Boolean, isBuyer: Boolean, itemId: UUID, deliveryForm: Form[DeliveryDetailsForm], transactionStatus: TransactionInfoStatus, errorMessage: Optional[String])(implicit nav: Nav)

@main(message("deliveryDetails")) {

    <h2>@message("deliveryDetails")</h2>

    @if(showInlineInstruction == true) {
        <p>@message("instruction.deliveryDetails")</p>
    }

    @foundationForm(deliveryForm, routes.TransactionController.submitDeliveryDetails(itemId.toString, transactionStatus.name, isBuyer)) {
        @if(errorMessage.isPresent) {
            <div class="alert callout">
                <i class="fi-alert"></i> @errorMessage.get()
            </div>
        }

        <div class="column row">
            @if(transactionStatus.equals(TransactionInfoStatus.NEGOTIATING_DELIVERY) && isBuyer) {
                @inputText(deliveryForm("addressLine1"))
            } else {
                @inputText(deliveryForm("addressLine1"),'readonly->'readonly)
            }
        </div>
        <div class="column row">
            @if(transactionStatus.equals(TransactionInfoStatus.NEGOTIATING_DELIVERY) && isBuyer) {
                @inputText(deliveryForm("addressLine2"))
            } else {
                @inputText(deliveryForm("addressLine2"),'readonly -> 'readonly)
            }
        </div>
        <div class="row">
            <div class="medium-6 columns">
                @if(transactionStatus.equals(TransactionInfoStatus.NEGOTIATING_DELIVERY) && isBuyer) {
                    @inputText(deliveryForm("city"))
                } else {
                    @inputText(deliveryForm("city"),'readonly -> 'readonly)
                }

            </div>
            <div class="medium-6 columns">
                @if(transactionStatus.equals(TransactionInfoStatus.NEGOTIATING_DELIVERY) && isBuyer) {
                    @inputText(deliveryForm("state"))
                } else {
                    @inputText(deliveryForm("state"),'readonly -> 'readonly)
                }
            </div>
        </div>

        <div class="row">
            <div class="medium-6 columns">
                @if(transactionStatus.equals(TransactionInfoStatus.NEGOTIATING_DELIVERY) && isBuyer) {
                    @inputText(deliveryForm("postalCode"), 'type -> "number")
                } else {
                    @inputText(deliveryForm("postalCode"), 'type -> "number",'readonly -> 'readonly)
                }
            </div>
            <div class="medium-6 columns">
                @if(transactionStatus.equals(TransactionInfoStatus.NEGOTIATING_DELIVERY) && isBuyer) {
                    @inputText(deliveryForm("country"))
                } else {
                    @inputText(deliveryForm("country"),'readonly -> 'readonly)
                }
            </div>
        </div>
        @if(transactionStatus.equals(TransactionInfoStatus.NEGOTIATING_DELIVERY) && isBuyer) {
            <input type="submit" class="button" value="@message("submitDeliveryDetails")"/>
        }
    }
}
